import Opt from '@/components/dt/info/Opt.js'
import rolesOpt from '@/biz/option/roles.js'
import dateOpt from '@/biz/option/date.js'
import tool from '@/common/tool'
import { Message } from 'view-design'

class Column extends Opt {

  constructor() {
    super()
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [{
        field: 'workNo',
        minWidth: 110,
        header: {
          filter: {
            key: 'workNo',
            title: '人员工号',
            placeholder: '请输入人员工号',
            input: {}
          }
        }
      }, {
        field: 'userName',
        minWidth: 110,
        header: {
          filter: {
            key: 'name',
            title: '人员姓名',
            placeholder: '请输入人员姓名',
            input: {}
          }
        }
      }, {
        field: 'phone',
        minWidth: 130,
        header: {
          filter: {
            key: 'phone',
            title: '人员手机号',
            placeholder: '请输入人员手机号',
            input: {}
          }
        }
      }, {
        field: 'name1',
        title: '移出事业部',
        minWidth: 150
      }, {
        field: 'name2',
        title: '移出子公司',
        minWidth: 150
      }, {
        field: 'name3',
        title: '移出事业处',
        minWidth: 150
      }, {
        field: 'name4',
        title: '移入事业部',
        minWidth: 150
      }, {
        field: 'name5',
        title: '移入子公司',
        minWidth: 150
      }, {
        field: 'name6',
        title: '移入事业处',
        minWidth: 150
      }, {
        field: 'roleName',
        minWidth: 180,
        header: {
          filter: rolesOpt.create({
            key: 'roleIds',
            title: '人员角色',
            multiple: true,
            maxTagCount: 2,
          })
        }
      }, {
        field: 'validate',
        minWidth: 100,
        header: {
          filter: {
            title: '人员状态',
            key: 'validate',
            placeholder: '请选择',
            select: {
              options: [
                { value: '启用', key: '1' },
                { value: '禁用', key: '2' }
              ]
            }
          }
        }
      }, {
        field: 'createTime',
        minWidth: 120,
        cell: {
          text: {
            type: 'date'
          }
        },
        header: {
          filter: dateOpt.range({
            title: '操作日期',
            startKey: 'startDate',
            endKey: 'endDate',
            disabled: (date) => {
              return date && date.valueOf() > Date.now();
            },
            check: (val) => {
              let y = tool.dateDiff(val.startDate, val.endDate).Y
              if (y >= 2) {
                Message.warning('任务过期时间跨度至多两年')
              }
              return !(y >= 2)
            }
          })
        }
      },
      {
        field: 'operationName',
        title: '操作人',
        minWidth: 140,
        cell: {
          value: (item) => `${item.operationName}(${item.operationWorkNo})`,
          text: {}
        }
      },
    ]
  }

}

export default Column
